from pwn import *
from hashlib import sha256
import random
import string

def sha256_def(x,sha256_hash):
    a = string.ascii_letters + string.digits
    for i1 in a:
        for i2 in a:
            for i3 in a:
                for i4 in a:
                    c=i1+i2+i3+i4+x
                    c=c.encode()
                    if sha256(c).hexdigest() == sha256_hash:
                        print(i1+i2+i3+i4)
                        return i1+i2+i3+i4
#nc 47.104.85.225 49803

sh = remote("node4.buuoj.cn",28554)
# context.log_level ='debug'
sh.recvuntil("(")
#截取后半断的字符串
sh.recvuntil("+")
str_x=sh.recvuntil(")").decode()[:-1]
sh.recvuntil("==")
#sha256的hash值
sha256_hash1=sh.recvuntil("\n").decode().strip()
data=sha256_def(str_x,sha256_hash1)
sh.sendline(data)

for i in range(777):
    sh.recvuntil("the ")
    str_x = sh.recvuntil("th").decode()[:-2]
    print(str_x)
    print(i)
    data=str(int(str_x)*4)
    sh.sendline(data)
    sh.recv()
sh.interactive()